在我的简单项目中,有一个按钮可以将主题从浅色变为深色,反之亦然,如下所示:import'package:flutter/material.dart';import'package:shared_preferences/shared_preferences.dart';import'dart:async';voidmain()=>runApp(MyApp());classMyAppextendsStatefulWidget{@overrideMyAppStatecreateState(){returnnewMyAppState();}}classMyAppStateextendsStat
几个小时以来,我一直在尝试覆盖我的应用主题,但没有成功,如果能获得任何帮助,我将不胜感激。我想我正在做的正是thisquestioner正在做,但对我来说,由于某种原因主题没有被覆盖,我不明白为什么。无论我做什么,文本“嘿”都不是白色的。任何想法为什么?谢谢。@overrideWidgetbuild(BuildContextcontext){finalThemeData_themeData=Theme.of(context);returnTheme(data:_themeData.copyWith(textTheme:_themeData.textTheme.copyWith(head
几个小时以来,我一直在尝试覆盖我的应用主题,但没有成功,如果能获得任何帮助,我将不胜感激。我想我正在做的正是thisquestioner正在做,但对我来说,由于某种原因主题没有被覆盖,我不明白为什么。无论我做什么,文本“嘿”都不是白色的。任何想法为什么?谢谢。@overrideWidgetbuild(BuildContextcontext){finalThemeData_themeData=Theme.of(context);returnTheme(data:_themeData.copyWith(textTheme:_themeData.textTheme.copyWith(head
我有这个:Widgetbuild(BuildContextcontext){returnMaterialApp(title:'AnApp',theme:ThemeData(primarySwatch:Colors.blueGrey,),home:MainWidget());}}所以我将primarySwatch颜色设置为blueGrey。如何在MainWidget类中访问这种颜色?我想设置一个与AppBar颜色相同的背景。 最佳答案 我不确定是否存在像这样在小部件内部使用primarySwatch的方法,但如果您正在寻找AppBar
我有这个:Widgetbuild(BuildContextcontext){returnMaterialApp(title:'AnApp',theme:ThemeData(primarySwatch:Colors.blueGrey,),home:MainWidget());}}所以我将primarySwatch颜色设置为blueGrey。如何在MainWidget类中访问这种颜色?我想设置一个与AppBar颜色相同的背景。 最佳答案 我不确定是否存在像这样在小部件内部使用primarySwatch的方法,但如果您正在寻找AppBar
我希望用户可以在我的应用中更改和保存主题颜色。但是,我不知道如何在应用程序开始运行时加载保存的主题颜色。比如我想直接在下方评论处加载保存的主题色。我尝试了SharedPreference。但是,SharedPreference实例需要使用await运行。这里好像不能用。有什么办法可以直接在这里加载保存的主题,而不是使用setState或类似的东西吗?import'package:flutter/material.dart';voidmain()=>runApp(newMyApp());classMyAppextendsStatelessWidget{@overrideWidgetbui
我希望用户可以在我的应用中更改和保存主题颜色。但是,我不知道如何在应用程序开始运行时加载保存的主题颜色。比如我想直接在下方评论处加载保存的主题色。我尝试了SharedPreference。但是,SharedPreference实例需要使用await运行。这里好像不能用。有什么办法可以直接在这里加载保存的主题,而不是使用setState或类似的东西吗?import'package:flutter/material.dart';voidmain()=>runApp(newMyApp());classMyAppextendsStatelessWidget{@overrideWidgetbui
如果我像这样向我的应用添加主题:classMyAppextendsStatelessWidget{@overrideWidgetbuild(BuildContextcontext){returnMaterialApp(debugShowCheckedModeBanner:false,theme:ThemeData(primaryColor:Color(0xff393e46),primaryColorDark:Color(0xff222831),accentColor:Color(0xff00adb5),backgroundColor:Color(0xffeeeeee),buttonTh
如果我像这样向我的应用添加主题:classMyAppextendsStatelessWidget{@overrideWidgetbuild(BuildContextcontext){returnMaterialApp(debugShowCheckedModeBanner:false,theme:ThemeData(primaryColor:Color(0xff393e46),primaryColorDark:Color(0xff222831),accentColor:Color(0xff00adb5),backgroundColor:Color(0xffeeeeee),buttonTh
如何制作自己的文字主题样式?我只找到这样的默认文本主题,但这还不够。textTheme:TextTheme(body1:TextStyle(),body2:TextStyle(),button:TextStyle(),caption:TextStyle(),display1:TextStyle(),display2:TextStyle(),display3:TextStyle(),display4:TextStyle(),headline:TextStyle(),overline:TextStyle(),subhead:TextStyle(),subtitle:TextStyle(),